<?

function newSpecial($data)
{
    $array = array();

    $title = get_the_title($data['slot']);

    $title = '[Slot ' . $data['slot'] . '] '
        .get_field('pid', getPitchID($data['slot']))
        . ', '
        . get_field('name', getVenueID($data['slot']))
        . ' | '
        . get_field('start_time', $data['slot'])
        . ' - '
        . get_field('end_time', $data['slot'])
        . ' - '
        . date('l, j F Y',strtotime($data['date']));

    // Create post object
    $postOptions = array(
        'post_title' => $title,
        'post_type' => 'special',
        'post_status' => 'publish',
        'post_author' => 1,
    );

    // Insert the post into the database
    $post_id = wp_insert_post($postOptions, $wp_error);

    wp_update_post(
        array(
            'ID' => $post_id,
            'post_name' => $post_id,
            'post_title' => '[Special ' . $post_id . '] ' . $title
        )
        , $wp_error
    );

    update_field('field_519f3dbe78e27', $data['slot'], $post_id);
    update_field('field_519f3dd678e28', $data['date'], $post_id);
    update_field('field_519f3e0e78e29', $data['price'], $post_id);

    $array['status'] = 'added post' . $post_id;
    $array['options'] = $data;
    $array['error'] = $wp_error;

    return $array;
}